package util;

import java.sql.*;

public class DbUtil {
        private static final String driverName="com.mysql.jdbc.Driver";//驱动器名称
        private static final String url="jdbc:mysql://127.0.0.1:3306/hospital?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai";//数据库地址
        private static final String user="root";//用户名
        private static final String password="wxy1919";//密码


        //获取数据库连接
    public static Connection getConnection() throws ClassNotFoundException, SQLException
    {
        Connection conn=null;
        Class.forName(driverName);
        conn= DriverManager.getConnection(url, user, password);
        return conn;
    }

    //释放资源
    public static void release(PreparedStatement pstmt, Connection conn)
    {
        release(null,pstmt,conn);
    }

    //释放资源
    public static void release(ResultSet rs, PreparedStatement pstmt, Connection conn)
    {

        try
        {
            if(rs !=null)
            {
                rs.close();
            }
            if(pstmt !=null)
            {
                pstmt.close();
            }
            if(conn !=null)
            {
                conn.close();
            }
        } catch (SQLException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
